class IUP_THEME
-- Creates a theme element to be applied to controls with features 
-- "set_theme" or "set_ntheme". The theme is a list of pair strings, the 
-- attribute (key) and the value to be applied to that attribute. The key of 
-- the attribute is the default IUP name of the attribute.
--
-- Only attributes that are registered in the element will receive its theme 
-- value.
--
-- Attributes that are registered as not being strings, read-only, write-only 
-- or callbacks will NOT be applied.
--
-- The theme can contain an specialized sub-theme for the element class. The 
-- element class name will be used with a "IUP" prefix to identify the 
-- sub-theme. For instance, if the element is a label, then an attribute called 
-- "IUPLABEL" can point to anohter theme name to be applied at the element 
-- additionally to the already applied attributes.
--
-- The global attribute DEFAULTTHEME can be applied to all elements during 
-- creation.

inherit
	IUP_WIDGET

insert
	IUP_INTERFACE

create
	theme

feature {ANY}

	theme (name: STRING)
		-- Creates a theme with the given name.
		local
			a_theme, p: POINTER
		do
			a_theme := int_theme
			set_widget(a_theme)

			p := int_set_widget_name(name.to_external, widget)

			--if p /= Void then
			--	io.put_string("There was a previous widget with this name. %N")
			--end
		end

	set_value_for_key (value, key: STRING)
		-- Add a pair key-value at the theme. The key is the default IUP name 
		-- of the attribute (like "SIZE", "MARGIN", "GAP", etc.). The value is 
		-- a valid value for that attribute.
		do
			iup_open.set_attribute(Current, key, value)
		end

feature {}

	-- Internal

	int_theme: POINTER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupUser()"
         }"
      end

	int_set_widget_name(name, wgt: POINTER): POINTER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupSetHandle"
         }"
      end

end

-- The MIT License (MIT)

-- Copyright (c) 2019 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
